PPG
 
Component PPG
Programmable pulse generation
Component Level: High
Typical Usage:
(Examples of a typical usage of the component in user code. For more information please see the page Component Code Typical Usage.)

Required component name is "PPG1".
There are the following four typical usage modes:

(1)
The easiest usage of the component is simple output signal generation with predefined period and duty. It's possible to change duty using method SetRatio.

 MAIN.C

void main(void)
{
  unsigned int i, j;
  for( i = 0; i<65535; ++i ) {
    PPG1_SetRatio16( i );      //change duty
    for( j=0; j<65535; ++j );  //delay
  }
  for(;;);
}
Note: The component may be also used without any method and event - only for settings of the output signal period and duty.

(2)
Usually it's better to change duty after the end of period, because this helps to avoid noises in the output signal. The property "Interrupt service/event" must be enabled for the support of OnEnd event.

 EVENTS.C

unsigned ratio = 0;
void PPG1_OnEnd(void)
{
  PPG1_SetRatio16( ++ratio );  //change duty
}

(3)
There are other advanced methods for changing the period and duty at runtime. It is possible to select one duty from the predefined list using SetRatioMode method or set the value from interval using SetDutyTicks and SetDutyTime methods (please refer to Timing dialog box).
It is possible to select one period from the predefined list using SetPeriodMode method or set the value from interval using SetPeriod and SetFreq methods (please refer to Timing dialog box).
In the following example the period is switched after each 255 period. The period mode is set sequentially from three predefined values.

 EVENTS.C

int rpt_cntr = 255, mode = 0;

void PPG1_OnEnd(void)
{

  if( --rpt_cntr==0 ) {  // If the event was generated 255times
    if( ++mode==3 ) mode = 0; // Select next mode of the period
    PPG1_SetPeriodMode( mode );// Set new period mode
    rpt_cntr = 255; // Set repeat counter
  }
}

(4)
Component initial level of the output signal can be changed using SetValue and ClrValue methods. These methods may be only used when the component is disabled.

 MAIN.C

void main(void)
{
  /* output signal synchronization */
  PPG1_Disable();  /* disable the component */
  PPG1_ClrValue(); /* set output level to LOW */
  PPG1_Enable();   /* enable the component */
}